<!--只要点击按钮就会触发-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>动态注册的onclick事件</title>
    <script type="text/javascript">
        window.onload = function () {
            var btnObj = document.getElementById('id0001');  // 通过id获取对象
            btnObj.onclick = function () {
                alert("动态注册的onclick事件");
            }
        }
    </script>
</head>
<body>
<button id="id0001">动态注册事件的按钮</button>

</body>
</html>